package main

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"go.mod/services"
	"go.mod/submodels"
	"time"
)

func sum(max int){
	result:=0
	for i:=1;i<=max;i++{
		result = result +1
	}
	fmt.Println(result)
}

func main()  {

	go sum(10000)
	time.Sleep(time.Second*10)

	result:=services.GetUser()
	fmt.Println(result)

	var sn submodels.SportsNews;
	sn.NewsID=123
	sn.NewsTitle="bac"
	sn.Tags=[]string{"足球","篮球","游泳"}
	fmt.Println(sn.ToJSON());




	db,err := sql.Open("mysql", "cj:34681011cjscsyyy@tcp(106.12.56.8:3306)/myjava?charset=utf8mb4")
	if err!=nil{
		fmt.Println("连接错"+err.Error())
		return
	}
	rows,err:=db.Query("select book_id,book_name from books")
	if err!=nil{
		fmt.Println("查询错误"+err.Error())
		return
	}

	//bookModel:=[]models.BookModel{}
	allRows:=make([]interface{},0)
	for rows.Next() {
		//temp:=models.BookModel{}
		//rows.Scan(&temp.BookId,&temp.BookName,&temp.BookPress)
		//fmt.Println(bookModel)
		//bookModel = append(bookModel, temp)
		oneRow:=make([]interface{},2)
		rows.Scan(&oneRow[0],&oneRow[1])
		for _,val:=range oneRow{
			v,ok:=val.([]byte)
			if(ok){
				fmt.Println(string(v))

			}		}
		allRows=append(allRows,oneRow)
	}

	/*fmt.Println(cap(bookModel))
	for i:=0;i< len(bookModel);i++  {
		fmt.Println(bookModel[i].ToJSON());
	}
	fmt.Println(cap(bookModel))*/




}

func getme(prefix string) (string,int){
	return prefix+"shenyi",19
}